package home.mutant.gauto.generative;

import home.mutant.gauto.ui.ResultFrame;
import home.mutant.gauto.utils.ImageUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MainNonGenetic
{
	private static final int NO_GENERATIONS = 200;
	List<byte[]> images = new ArrayList<byte[]>();
	List<Integer> numberNeuronsPerLayer;
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException
	{
		List<Integer> neurons = new ArrayList<Integer>();
		neurons.add(16);
		neurons.add(100);
		new MainNonGenetic(neurons).run();
	}

	private void run()
	{
		ResultFrame frame = new ResultFrame(1200, 600);
		WeightsModel model = new WeightsModel(numberNeuronsPerLayer, false);
		for (int i=0; i<NO_GENERATIONS;i++)
		{
			model.learnStep2(images);
			if (i%10==0)
				frame.showModel2by2(model,10);
		}
		
		for (int i = 0; i<images.size();i++)
		{
			System.out.println(model.test(images.get(i)));
		}
			
	}

	public MainNonGenetic(List<Integer> numberNeuronsPerLayer) throws IOException
	{
		this.numberNeuronsPerLayer = new ArrayList<Integer>(numberNeuronsPerLayer);
		loadImages();
	}
	private void loadImages() throws IOException
	{
		for(int i=1;i<=8;i++)
		{
			String resourceClass = "/A" +i + ".bmp";
			byte[] image = new byte[100];
			ImageUtils.readResourceImage(resourceClass, image);
			images.add(image);
		}
	}
}
